// index.js
// 获取应用实例
const app = getApp()
const db = wx.cloud.database();

Page({
  data: {
    swipers: ['red','blue','pink','green'],
    list: []
  },
  page: 1,
  fetchList() {
    db.collection('mock_product').limit(8).skip((this.page-1)*8).get().then(res => {
      this.setData({
        list: (this.page === 1 ? [] : this.data.list).concat(res.data)
      })
    })
  },
  onLoad() {
    this.fetchList()
  },
  onReachBottom() {
    this.page+= 1;
    this.fetchList()
  },
  onPullDownRefresh() {
    this.page = 1;
    this.fetchList()
  },
  goDetail(e) {
    const {id} = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + id,
    })
  },
  goSearch() {
    wx.navigateTo({
      url: '/pages/search/search',
    })
  }
})
